/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BO;

import java.io.Serializable;
import java.util.Comparator;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Wase
 */
@Entity
@Table(name = "postit")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Postit.findAll", query = "SELECT p FROM Postit p"),
    @NamedQuery(name = "Postit.findById", query = "SELECT p FROM Postit p WHERE p.id = :id"),
    @NamedQuery(name = "Postit.findByContent", query = "SELECT p FROM Postit p WHERE p.content = :content"),
    @NamedQuery(name = "Postit.findByDatePosted", query = "SELECT p FROM Postit p WHERE p.datePosted = :datePosted")})
public class Postit implements Serializable, Comparable<Postit> {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Column(name = "content")
    private String content;
    @Basic(optional = false)
    @Column(name = "datePosted")
    @Temporal(TemporalType.TIMESTAMP)
    private Date datePosted;
    @JoinColumn(name = "userId", referencedColumnName = "id")
    @ManyToOne(optional = false)
    private User userId;

    public Postit() {
    }

    public Postit(Integer id) {
        this.id = id;
    }

    public Postit(Integer id, Date datePosted) {
        this.id = id;
        this.datePosted = datePosted;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getDatePosted() {
        return datePosted;
    }

    public void setDatePosted(Date datePosted) {
        this.datePosted = datePosted;
    }

    public User getUserId() {
        return userId;
    }

    public void setUserId(User userId) {
        this.userId = userId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Postit)) {
            return false;
        }
        Postit other = (Postit) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "BO.Postit[ id=" + id + " ]";
    }

    @Override
    public int compareTo(Postit t) {
        long d1 = this.getDatePosted().getTime();
        long d2 = t.getDatePosted().getTime();
        if (d1 > d2) {
            return -1;
        } else if (d1 < d2) {
            return 1;
        } else {
            return 0;
        }
    }
    
}
